package com.example.girdviewtest;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.GridView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;


public class GMainActivity extends AppCompatActivity {
    private int[]  pp= new int[]{R.drawable.img01,R.drawable.img02,
            R.drawable.img03,R.drawable.img04,R.drawable.img05,R.drawable.img06,R.drawable.img07,R.drawable.img08,R.drawable.img09

    };

    //private int i;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gmain);

        GridView gridview = (GridView)findViewById(R.id.gridView);
        List<Map<String,Object>> list = new ArrayList<Map<String, Object>>();
        for (int i=0 ; i<pp.length ; i++){
            Map<String,Object> map = new HashMap<String, Object>();
            map.put("image1",pp[i]);
            list.add(map);
        }
        SimpleAdapter simpleAdapter = new SimpleAdapter(this,list,R.layout.cell,new String[]{"image1"},new int[]{R.id.imageview1});//定义整型数组来指定图片的组件id
        gridview.setAdapter(simpleAdapter);

    }
}
